package com.cea.papyrus.core.treeeditpart;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.gef.RootEditPart;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Event;

import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.treeeditpart.pseudoelement.EventsGroup;

/**
 * Tree edit part for events groups
 */
public class GroupingEventsTreeEditPart extends GroupingTreeEditPart {

	/** associated pseudo element */
	protected EventsGroup eventsGroup;
	
	/**
	 * @param element
	 * @param modelManager
	 */
	public GroupingEventsTreeEditPart(EventsGroup eventsGroup, ModelManager modelManager) {
		super(eventsGroup, modelManager);
		this.eventsGroup = eventsGroup;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.treeeditpart.CommonTreeEditPart#getText()
	 */
	@Override
	public String getText() {
		return "Events ("+getModelChildren().size()+")";
	}
	/**
	 * {@inheritDoc}
	 */
	public RootEditPart getRoot() {
		if (getParent()==null)
		{return null;}
		else {return getParent().getRoot();}
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.treeeditpart.CommonTreeEditPart#getImage()
	 */
	@Override
	public Image getImage() {
		return PapyrusPlugin.getImage(PapyrusPlugin.PAPYRUS_ICONS_16x16+"EventsGroup.gif");
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
	 */
	@Override
	protected List<Element> getModelChildren() {
		List<Element> contained = new ArrayList<Element>();
		org.eclipse.uml2.uml.Package package_ = eventsGroup.getPackage();
		Iterator<Element> iter = package_.getOwnedElements().iterator();
		while(iter.hasNext()){
			Element elt = (Element)iter.next();
			if(elt instanceof Event)
				contained.add(elt);
		}
		return contained;
	}
}
